home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Aminet
/
comm
/
net
/
amitcp2_x_gcc.lha
/
RCS.RCSfiles
/
autoinitd.c,v
< prev
next >
Wrap
Text File
|
1994-01-12
|
5KB
|
223 lines
head 1.2;
access;
symbols;
locks
jasegler:1.2; strict;
comment @ * @;
1.2
date 94.01.12.18.40.51; author jasegler; state Exp;
branches;
next 1.1;
1.1
date 94.01.12.18.12.04; author jasegler; state Exp;
branches;
next ;
desc
@@
1.2
log
@*** empty log message ***
@
text
@char RCS_ID_AUTOINITD_C[] = "$Id: autoinitd.c,v 1.1 1994/01/12 18:12:04 jasegler Exp jasegler $";
/*
* SAS C Autoinitialization Functions for Daemons
*
* Author: ppessi <Pekka.Pessi@@hut.fi>
*
* Copyright © 1993 AmiTCP/IP Group, <amitcp-group@@hut.fi>
* Helsinki University of Technology, Finland.
* All rights reserved.
*
* Created : Mon May 24 19:30:06 1993 ppessi
* Last modified: Mon Jul 19 14:24:30 1993 jraja
*/
/****** inetdlib.doc/autoinitd **********************************************
* NAME
* autoinitd - SAS C Autoinitialization Functions for Daemons
*
* SYNOPSIS
* void _STIopenSockets(void);
* void _STDcloseSockets(void);
* long server_socket;
*
* DESCRIPTION
* These are SASC autoinitialization functions for internet daemons
* started by inetd, Internet super-server. Upon startup, the server
* socket is obtained with ObtainSocket() library call. If successful,
* the socket id is stored to the global variable server_socket. If the
* socket is not obtainable, the server_socket contains value -1.
* If the server_socket is not valid, the server may try to accept() a
* new connection and act as a stand-alone server.
*
* RESULT
* server_socket - positive socket id for success or -1 for failure.
*
* NOTES
* _STIopenSockets() also checks that the system version is at
* least 37. It puts up a requester if the bsdsocket.library
* is not found or is of wrong version.
*
* The autoinitialization and autotermination functions are
* features specific to the SAS C6. However, these functions
* can be used with other (ANSI) C compilers, too. Example
* follows:
*
* \* at start of main() *\
*
* atexit(_STDcloseSockets);
* _STDopenSockets();
*
* AUTHOR
* Jarno Rajahalme, Pekka Pessi,
* the AmiTCP/IP Group <amitcp-group@@hut.fi>,
* Helsinki University of Technology, Finland.
*
* SEE ALSO
* serveraccept(), netutil/inetd
*
*****************************************************************************
*
*/
#include <exec/types.h>
#include <exec/libraries.h>
#include <dos/dosextens.h>
#include <intuition/intuition.h>
#ifdef __GNUC__
#include <clib/socket_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#endif
#ifdef _DCC
#include <clib/socket_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#endif
#ifdef __SASC__
#include <proto/socket.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#endif
#include <stdlib.h>
#include <inetd.h>
struct Library *SocketBase = 0L;
int errno = 0;
long server_socket = -1;
#ifndef SOCKETNAME
#define SOCKETNAME "bsdsocket.library"
#endif
#define SOCKETVERSION 2 /* minimum bsdsocket version to use */
#ifdef __SASC__
extern STRPTR _ProgramName; /* SAS startup module defines this :-) */
#endif
#ifdef __GNUC__
char _ProgramName[] = "GNU C Program";
#endif
#ifdef _DCC
char _ProgramName[] = "DCC Program";
#endif
void
_STIopenSockets (void)
{
struct Process *me = (struct Process *) FindTask (0L);
struct DaemonMessage *dm = (struct DaemonMessage *) me->pr_ExitData;
static short done = 0;
struct Library *IntuitionBase;
STRPTR errorStr;
if (done++) /* try only once (SAS/C 6.2 liked to call this twice) */
return;
/*
* Check OS version
*/
if ((*(struct Library **) 4)->lib_Version < 37)
exit (20);
/*
* Open bsdsocket.library
*/
if ((SocketBase = OpenLibrary (SOCKETNAME, SOCKETVERSION)) != NULL)
{
/*
* Succesfull. Now tell bsdsocket.library the address of our errno
*/
SetErrnoPtr (&errno, sizeof (errno));
if (dm && server_socket == -1)
{
server_socket = ObtainSocket (dm->dm_Id, dm->dm_Family, dm->dm_Type, 0);
if (server_socket == -1)
exit (DERR_OBTAIN);
}
return;
}
else
errorStr = "AmiTCP/IP version 2 or later must be started first.";
IntuitionBase = OpenLibrary ("intuition.library", 36);
if (IntuitionBase != NULL)
{
struct EasyStruct libraryES;
libraryES.es_StructSize = sizeof (libraryES);
libraryES.es_Flags = 0;
libraryES.es_Title = _ProgramName;
libraryES.es_TextFormat = errorStr;
libraryES.es_GadgetFormat = "Exit %s";
EasyRequestArgs (NULL, &libraryES, NULL, (APTR) & _ProgramName);
CloseLibrary (IntuitionBase);
}
exit (DERR_LIB);
}
void
_STDcloseSockets (void)
{
if (SocketBase)
{
CloseLibrary (SocketBase);
SocketBase = NULL;
}
}
@
1.1
log
@Initial revision
@
text
@d1 1
a1 1
char RCS_ID_C[] = "$Id: autoinitd.c,v 1.4 1993/07/19 11:24:40 jraja Exp $";
@